package com.wsoft.system.controller;

import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import com.wsoft.system.dto.SysDataPermDto;
import com.wsoft.system.query.dataPerm.DataPermInsertQuery;
import com.wsoft.system.query.dataPerm.DataPermUpdateQuery;
import com.wsoft.system.query.perm.SysDataPermReq;
import com.wsoft.system.service.ISysDataPermService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 数据权限表 前端控制器
 * </p>
 *
 * @author kyle
 * @since 2024年08月29日 10:34:35
 */
@RestController
@Tag(name = "数据权限")
@RequestMapping("/sys/dataPerm")
public class SysDataPermController {
    @Resource
    private ISysDataPermService sysDataPermService;
    @Operation(summary = "数据权限列表(分页)",description = "分页")
    @PostMapping("/list")
    public ResponseResult pageList(@RequestBody @Valid SysDataPermReq dto) {
        return ResponseResult.success(ResponsePage.restPage(sysDataPermService.pageDataPerm(dto)));
    }

    @Operation(summary = "新增数据权限",description = "新增数据权限")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid DataPermInsertQuery query) {
        boolean b = sysDataPermService.insert(query);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
          return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "编辑数据权限",description = "编辑数据权限")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid DataPermUpdateQuery query) {
        boolean b = sysDataPermService.update(query);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "删除数据权限",description = "删除数据权限")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = sysDataPermService.delete(id);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
    @Operation(summary = "查看数据权限详情",description = "查看数据权限详情")
    @GetMapping("/get")
    public ResponseResult getDataPerm(@RequestParam("id") Long id) {
        return ResponseResult.success(sysDataPermService.getDataPerm(id));
    }

//    @Operation(summary = "查看所有数据权限",description = "查看所有数据权限")
//    @GetMapping("/getAllDataPerm")
//    @GetRedisCache(type = RedisKeyConstant.DATA_PERM_ALL)
//    public List<SysDataPermEntity> getAllDataPerm() {
//        return sysDataPermService.list();
//    }
}
